/**
 * 处理各报表私有的逻辑
 * 通过id获取
 *
 * 如需增加其他请参考universal-report中的report-private.service
 *
 * 目前配置包括
 * [reportId]: {
 *      // 用于生成当前图形化报表的searchForm，因为图形化报表现在不支持配置searchForm，所以前端写死
 *      searchFormList: [{
 *          code,
 *          label,
 *          dependencyCode
 *      }],
 *
 *      // 核心函数，用于生成页面各report的config及render函数
 *      // config目前分三种：概览，常规图表，table
 *      // 概览：
 *      // 常规图表：props必须提供onRef
 *      // table：fetchMethod不需要返回dataLength和options，因为table的数据由reportTable内部处理
 *      reportConfig: (context) => {
 *        return {
 *            [reportType]: {
 *                title: "",
 *                isLoading: false, // 标记当前报表是否正在加载
 *                fetchMethod: () => {},  // 当前报表获取数据方法，通常返回options和dataLength
 *                options: [],  // 数据项
 *                dataLength: 0,  // 数据项总数，如果是table请保证传一个非0常量，因为table使用reportWrapper包裹
 *                ref: null,  // 保存当前报表的ref
 *                activeConfig: { // 用于点击时修改searchParams
 *                    key: '',
 *                    array: true
 *                },
 *                showLabel: true, // 是否展示柱状图上的数字及百分比
 *                isTable: false,
 *                columns: [],  // isTable为真时必传
 *                render: ({config, context, reportType}) => {} // 报表渲染方法 config即当前配置项
 *            }
 *        }
 *      }
 *
 *     // 生成searchForm时对对应筛选器进行特殊处理，一定要同步
 *     // 本来是支持生成searchForm时异步处理的，后来思考了很久删掉了支持的代码
 *     // 就两个原因：麻烦，非常影响用户体验
 *     searchItemHandler: {
 *         [criteriaCode]: ({context, code, name}) => {
 *             return {}  // 必须返回一个筛选器对象
 *         }
 *     },
 *
 *     // 获取数据前对接口参数处理
 *     // 现在主要用于审批效率分析图表
 *     fetchInterceptor: (params) => {
 *        return params
 *     }
 * }
 *
 */
import { messages } from "share/common";
import React from "react";
import FeePrivateConfig from "./report-private-config/fee-report"
import LoanFeePrivateConfig from "./report-private-config/loan-fee-report"
import PersonnelFeePrivateConfig from "./report-private-config/personnel-fee-report"
import ApproveEfficiencyPrivateConfig from "./report-private-config/approve-efficiency-report"
import CompliancePrivateConfig from "./report-private-config/compliance-detail-report"
import ContractPrivateConfig from "./report-private-config/contract-report"
import RSCService from "../travel-report/report-search-components.service";
const { getErStatus } = RSCService;

const LOAN_FEE_REPORT = '10012';  // 借款分析图表
const FEE_REPORT = '10010';  // 费用分析图表
const PERSONNEL_FEE_REPORT = '10011';  // 个人费用分析图表
const APPROVE_EFFICIENCY_REPORT = '30001';  // 审批效率分析图表
const COMPLIANCE_DETAIL_REPORT = '32';  // 合规明细图表
const CONTRACT_REPORT = '41';  // 合同分析图表

export default {
  [LOAN_FEE_REPORT]: { // 借款分析图表
    searchFormList: [
      {
        code: 'filterSetOfBooksId',
        label: messages('finance-7.key215')/*账套(单选)*/,
      },
      {
        code: 'filterYear',
        label: messages('finance-7.key216')/*年份(单选)*/,
      },
      {
        code: 'filterYearMonths',
        label: messages('finance-7.key217')/*月份(多选)*/,
      },
      {
        code: 'filterCompanyOids',
        label: messages('finance-7.key218')/*借款公司（多选）*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterDepartmentCodes',
        label: messages('finance-7.key219')/*借款部门（多选）*/,
      },
      {
        code: 'recipientTypes',
        label: messages('finance-7.key220')/*收款方类型（多选）*/,
      },
      {
        code: 'filterBalanceType',
        label: messages('finance-7.key221')/*统计视角*/,
      }
    ],
    reportConfig: LoanFeePrivateConfig,
  },
  [PERSONNEL_FEE_REPORT]: {  // 个人费用分析图表
    searchFormList: [
      {
        code: 'filterSetOfBooksId',
        label: messages('finance-7.key215')/*账套(单选)*/,
      },
      {
        code: 'filterDateType',
        label: messages('finance-7.key222')/*日期类型*/,
      },
      {
        code: 'filterYear',
        label: messages('finance-7.key216')/*年份(单选)*/,
      },
      {
        code: 'filterYearMonths',
        label: messages('finance-7.key217')/*月份(多选)*/,
      },
      {
        code: 'filterFormOids',
        label: messages('finance-7.key223')/*报销单类型(多选)*/,
        dependencyCode: 'filterDateType',
      },
      {
        code: 'filterStatus',
        label: messages('finance-7.key224')/*报销单状态(多选)*/,
        dependencyCode: 'filterDateType',
      },
      {
        code: 'filterExpenseTypeIds',
        label: messages('finance-7.key225')/*费用类型(多选)*/,
      }
    ],
    searchItemHandler: {
      'filterSetOfBooksId': (item) => {
        item.props.disabled = true;
        item.tagUnclosed = true;
        return item;
      }
    },
    reportConfig: PersonnelFeePrivateConfig,
  },
  [FEE_REPORT]: {
    searchFormList: [
      {
        code: 'filterSetOfBooksId',
        label: messages('finance-7.key215')/*账套(单选)*/,
      },
      {
        code: 'filterExpAnalyzeDateType',
        label: messages('finance-7.key222')/*日期类型*/,
      },
      {
        code: 'filterYear',
        label: messages('finance-7.key216')/*年份(单选)*/,
      },
      {
        code: 'filterYearMonths',
        label: messages('finance-7.key217')/*月份(多选)*/,
      },
      {
        code: 'filterCompanyOids',
        label: messages('finance-7.key226')/*公司(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterDepartmentCodes',
        label: messages('finance-7.key227')/*部门(多选)*/,
      },
      {
        code: 'filterIncludeSubDepts',
        label: messages('finance-7.key228')/*是否包含子部门*/,
      },
      {
        code: 'filterFormOids',
        label: messages('finance-7.key223')/*报销单类型(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterStatus',
        label: messages('finance-7.key224')/*报销单状态(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'searchCostCenterCommands',
        label: messages('finance-7.key155')/*成本中心*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterApplicantOids',
        label: messages('finance-7.key229')/*费用所属人员*/,
      },
      {
        code: 'filterExpenseTypeIds',
        label:  messages('finance-7.key225')/*费用类型(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterShowYOY',
        label: messages('finance-7.key230')/*趋势按月同比*/
      }
    ],
    reportConfig: FeePrivateConfig,
    searchItemHandler: {
      'filterDepartmentCodes': (item) => {
        item.component = 'Chooser';
        item.props = {
          type: 'department',
          labelKey: 'name',
          valueKey: 'departmentCode',
          single: false,
          listExtraParams: { status: 1002 },
        };
        item.hasValue = value => value && value[0];
        item.parser = value => {
          if (value && value.length) {
            return { filterDepartmentCodes: value.map(item => item.departmentCode) };
          }
          return { departmentCode: void 0 };
        };
        item.tagParser = value => value.map(item => item.name).join(',');
        return item;
      }
    },
  },
  [APPROVE_EFFICIENCY_REPORT]: {
    searchFormList: [
      {
        code: 'filterYear',
        label: messages('finance-7.key216')/*年份(单选)*/,
      },
      {
        code: 'filterYearMonths',
        label: messages('finance-7.key217')/*月份(多选)*/,
      },
      {
        code: 'approverDutyCode',
        label: messages('finance-7.key231')/*职务*/,
      },
      {
        code: 'approverTitle',
        label: messages('finance-7.key232')/*职位*/,
      },
      {
        code: 'filterCompanyOids',
        label: messages('finance-7.key233')/*审批人公司*/,
      },
      {
        code: 'filterDepartmentCodes',
        label: messages('finance-7.key234')/*审批人部门*/,
      },
      {
        code: 'filterApprovalOids',
        label: messages('finance-7.key235')/*审批人*/,
      }
    ],
    reportConfig: ApproveEfficiencyPrivateConfig,
    fetchInterceptor: params => {
      /**
       * 表单平均时长和表单平均节点数都是筛选formName
       * 但是为了避免点击时相同的activeConfig导致每次formName被重置（重置原因见getSpecificReportData中的注释
       * 所以分别取名为formName1和formName2
       * 而后在这里进行重新赋值
       */
      let newParams = {...params};
      newParams.formName = params.formName1 || params.formName2;
      return newParams;
    }
  },
  [COMPLIANCE_DETAIL_REPORT] : {
    searchFormList: [
      {
        code: 'filterSetOfBooksId',
        label: messages('finance-7.key215')/*账套(单选)*/,
      },
      {
        code: 'filterYear',
        label: messages('finance-7.key236')/*费用发生年份(单选)*//*年(单选)*/,
      },
      {
        code: 'filterYearMonths',
        label: messages('finance-7.key237')/*费用发生月份(多选)*//*月(多选)*/,
      },
      {
        code: 'filterAuditApprovalDate',
        label: messages('finance-7.key102')/*审核通过日期*//*审核通过日期(单选)*/,
      },
      {
        code: 'filterCompanyOids',
        label: messages('finance-7.key226')/*公司(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterDepartmentCodes',
        label: messages('finance-7.key227')/*部门(多选)*/,
      },
      {
        code: 'filterStatus',
        label: messages('finance-7.key224')/*报销单状态(多选)*/,
        dependencyCode: 'filterSetOfBooksId',
      },
      {
        code: 'filterAmountPercent',
        label: messages('finance-7.key97')/*实报金额占比*/
      },
      {
        code: 'filterExpOwner',
        label: messages('finance-7.key238')/*费用归属人(多选)*/,
      }
    ],
    reportConfig: CompliancePrivateConfig,
    searchItemHandler: {
      // graphic-report.service中的filterStatus，获取的是带消费商的报销单状态（systemCustomEnumerationType为5030）
      // 此处的是不带消费商的（systemCustomEnumerationType为5002）
      'filterStatus': (item) => {
        item.props.selectorItem.service = getErStatus
        return item;
      }
    },
  },
  [CONTRACT_REPORT]: {
    searchFormList: [
      {
        code: 'filterSetOfBooksId',
        label: messages('finance-7.key215')/*账套(单选)*/,
      },
      {
        code: 'filterYear',
        label: messages('finance-7.key239')/*签署日期年份(单选)*/,
      },
      {
        code: 'filterCompanyOids',
        label: messages('finance-7.key240')/*合同公司(多选)*/,
        dependencyCode: 'filterSetOfBooksId'
      },
      {
        code: 'filterContractTypes',
        label: messages('finance-7.key241')/*合同类型(多选)*/,
      },
      {
        code: 'filterContractStatus',
        label: messages('finance-7.key242')/*合同状态(多选)*/,
      }
    ],
    reportConfig: ContractPrivateConfig
  }
}
